/************************************************************
   Copyright 2008 Abhinav Pobbati

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*************************************************************/

#include "HkPrerequisites.h"

#include "Havok4Xna/Common/Base/Math/HkTransform.h"
#include "Havok4Xna/Common/Base/Math/HkMatrix3.h"
#include "Havok4Xna/Common/Base/Math/HkQuaternion.h"
#include "Havok4Xna/Common/Base/Math/HkQsTransform.h"
#include "Havok4Xna/Common/Base/Math/HkVector4.h"

namespace Havok4Xna {
	HkTransform::HkTransform() {
		_setThis(new hkTransform(), true);
	}
	HkTransform::HkTransform(HkRotation ^r, HkVector4 ^v) {
		_setThis(new hkTransform(r->_ref(), v->_ref()), true);
	}
	HkTransform::HkTransform(HkTransform ^t) {
		_setThis(new hkTransform(t->_ref()), true);
	}
	HkTransform::HkTransform(HkQuaternion ^q, HkVector4 ^v) {
		_setThis(new hkTransform(q->_ref(), v->_ref()), true);
	}
	void HkTransform::Set(HkQuaternion ^q, HkVector4 ^v) {
		_this()->set(q->_ref(), v->_ref());
	}
	void HkTransform::SetIdentity() {
		_this()->setIdentity();
	}
	bool HkTransform::IsApproximatelyEqual(HkTransform ^t, float epsilon) {
		return _this()->isApproximatelyEqual(t->_ref(), epsilon);
	}
	void HkTransform::SetRotation(HkQuaternion ^q) {
		_this()->setRotation(q->_ref());
	}
	void HkTransform::SetInverse(HkTransform ^t) {
		_this()->setInverse(t->_ref());
	}
	void HkTransform::SetMul(HkTransform ^t1, HkTransform ^t2) {
		_this()->setMul(t1->_ref(), t2->_ref());
	}
	void HkTransform::SetMul(HkQsTransform ^t1, HkTransform ^t2) {
		_this()->setMul(t1->_ref(), t2->_ref());
	}
	void HkTransform::SetMulInverseMul(HkTransform ^t1, HkTransform ^t2) {
		_this()->setMulInverseMul(t1->_ref(), t2->_ref());
	}
	void HkTransform::SetMulEq(HkTransform ^t) {
		_this()->setMulEq(t->_ref());
	}
	void HkTransform::SetRows4(HkVector4 ^r0, HkVector4 ^r1, HkVector4 ^r2, HkVector4 ^r3) {
		_this()->setRows4(r0->_ref(), r1->_ref(), r2->_ref(), r3->_ref());
	}
	void HkTransform::SetMulMulInverse(HkTransform ^a, HkTransform ^b) {
		_this()->setMulMulInverse(a->_ref(), b->_ref());
	}
	bool HkTransform::IsOk() {
		return _this()->isOk();
	}
	IMPL_COMPLEX_PROPERTY_GETTERSETTER(
		HkTransform, Translation, HkVector4,
		hkTransform, getTranslation, setTranslation, hkVector4);
	IMPL_COMPLEX_PROPERTY_GETTERSETTER(
		HkTransform, Rotation, HkRotation,
		hkTransform, getRotation, setRotation, hkRotation);


	HkSweptTransform::HkSweptTransform() {
		_setThis(new hkSweptTransform(), true);
	}
	void HkSweptTransform::ApproxTransformAt(float time, HkTransform ^transformOut) {
		_this()->approxTransformAt(time, transformOut->_ref());
	}
	float HkSweptTransform::GetInterpolationValue(float t) {
		return _this()->getInterpolationValue(t);
	}
	float HkSweptTransform::GetBaseTime() {
		return _this()->getBaseTime();
	}
	float HkSweptTransform::GetInvDeltaTime() {
		return _this()->getInvDeltaTime();
	}
	void HkSweptTransform::InitSweptTransform(HkVector4 ^position, HkQuaternion ^rotation) {
		_this()->initSweptTransform(position->_ref(), rotation->_ref());
	}

	IMPL_COMPLEX_PROPERTY_GETSET(HkSweptTransform, CenterOfMass0, HkVector4, hkSweptTransform, m_centerOfMass0, hkVector4);
	IMPL_COMPLEX_PROPERTY_GETSET(HkSweptTransform, CenterOfMass1, HkVector4, hkSweptTransform, m_centerOfMass1, hkVector4);
	IMPL_COMPLEX_PROPERTY_GETSET(HkSweptTransform, CenterOfMassLocal, HkVector4, hkSweptTransform, m_centerOfMassLocal, hkVector4);
	IMPL_COMPLEX_PROPERTY_GETSET(HkSweptTransform, Rotation0, HkQuaternion, hkSweptTransform, m_rotation0, hkQuaternion);
	IMPL_COMPLEX_PROPERTY_GETSET(HkSweptTransform, Rotation1, HkQuaternion, hkSweptTransform, m_rotation1, hkQuaternion);
}
